package com.oc.mba.dao.impl;

import java.util.List;


import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.oc.mba.dao.ContactDAO;
import com.oc.mba.entity.OcContacts;

@Repository
public class ContactDAOImpl implements ContactDAO {

	@Autowired
	private SessionFactory sessionFactory;

	public void addContact(OcContacts contact) {
		sessionFactory.getCurrentSession().save(contact);
	}

	public List<OcContacts> listContact() {

		return sessionFactory.getCurrentSession().createQuery("from OcContacts").list();
	}

	public void removeContact(Integer id) {
		OcContacts contact = (OcContacts) sessionFactory.getCurrentSession().load(
				OcContacts.class, id);
		if (null != contact) {
			sessionFactory.getCurrentSession().delete(contact);
		}

	}
}
